package com.google.android.material.snackbar;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.Looper;
import android.os.Message;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.ViewParent;
import android.view.accessibility.AccessibilityManager;
import android.widget.FrameLayout;
import androidx.annotation.IntRange;
import androidx.annotation.RestrictTo;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.ViewCompat;
import com.google.android.material.behavior.SwipeDismissBehavior;
import com.huawei.hwphy2d.physical.util.BarrierParameters;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import o.aqu.d;
import o.aqu.n;
import o.aqv;
import o.asr;
import o.ast;
import o.ik;

public abstract class BaseTransientBottomBar<B extends BaseTransientBottomBar<B>> {
    private static final boolean ˋ;
    static final Handler ˎ = new Handler(Looper.getMainLooper(), new Callback() {
        public boolean handleMessage(Message message) {
            switch (message.what) {
                case 0:
                    ((BaseTransientBottomBar) message.obj).ˏ();
                    return true;
                case 1:
                    ((BaseTransientBottomBar) message.obj).ˏ(message.arg1);
                    return true;
                default:
                    return false;
            }
        }
    });
    private static final int[] ॱ = new int[]{d.ͺ};
    private final AccessibilityManager ʻ;
    private final ViewGroup ʼ;
    private List<BaseCallback<B>> ʽ;
    final o.asr.a ˊ;
    protected final e ˏ;
    private Behavior ॱॱ;
    private final ast ᐝ;

    @RestrictTo({RestrictTo.d.LIBRARY_GROUP})
    protected interface c {
        void ॱ(View view, int i, int i2, int i3, int i4);
    }

    @RestrictTo({RestrictTo.d.LIBRARY_GROUP})
    protected interface a {
        void ˊ(View view);

        void ˎ(View view);
    }

    public static abstract class BaseCallback<B> {

        @RestrictTo({RestrictTo.d.LIBRARY_GROUP})
        @Retention(RetentionPolicy.SOURCE)
        public @interface DismissEvent {
        }

        public void ˊ(B b, int i) {
        }

        public void ॱ(B b) {
        }
    }

    public static class Behavior extends SwipeDismissBehavior<View> {
        private final b ʽ = new b(this);

        private void ˏ(BaseTransientBottomBar<?> baseTransientBottomBar) {
            this.ʽ.ˎ(baseTransientBottomBar);
        }

        public boolean ˋ(View view) {
            return this.ʽ.ˊ(view);
        }

        public boolean ˎ(CoordinatorLayout coordinatorLayout, View view, MotionEvent motionEvent) {
            this.ʽ.ˎ(coordinatorLayout, view, motionEvent);
            return super.ˎ(coordinatorLayout, view, motionEvent);
        }
    }

    @RestrictTo({RestrictTo.d.LIBRARY_GROUP})
    @IntRange(from = 1)
    @Retention(RetentionPolicy.SOURCE)
    public @interface Duration {
    }

    @RestrictTo({RestrictTo.d.LIBRARY_GROUP})
    public static class b {
        private o.asr.a ˋ;

        public b(SwipeDismissBehavior<?> swipeDismissBehavior) {
            swipeDismissBehavior.ˋ((float) BarrierParameters.RESTITUTION);
            swipeDismissBehavior.ˏ(0.6f);
            swipeDismissBehavior.ˏ(0);
        }

        public void ˎ(BaseTransientBottomBar<?> baseTransientBottomBar) {
            this.ˋ = baseTransientBottomBar.ˊ;
        }

        public boolean ˊ(View view) {
            return view instanceof e;
        }

        public void ˎ(CoordinatorLayout coordinatorLayout, View view, MotionEvent motionEvent) {
            switch (motionEvent.getActionMasked()) {
                case 0:
                    if (coordinatorLayout.ˋ(view, (int) motionEvent.getX(), (int) motionEvent.getY())) {
                        asr.ॱ().ˏ(this.ˋ);
                        return;
                    }
                    return;
                case 1:
                case 3:
                    asr.ॱ().ॱ(this.ˋ);
                    return;
                default:
                    return;
            }
        }
    }

    @RestrictTo({RestrictTo.d.LIBRARY_GROUP})
    protected static class e extends FrameLayout {
        private a ˊ;
        private final o.ik.a ˋ;
        private final AccessibilityManager ˎ;
        private c ˏ;

        protected e(Context context) {
            this(context, null);
        }

        protected e(Context context, AttributeSet attributeSet) {
            super(context, attributeSet);
            TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, n.ˎꓸ);
            if (obtainStyledAttributes.hasValue(n.ˎـ)) {
                ViewCompat.ˋ(this, (float) obtainStyledAttributes.getDimensionPixelSize(n.ˎـ, 0));
            }
            obtainStyledAttributes.recycle();
            this.ˎ = (AccessibilityManager) context.getSystemService("accessibility");
            this.ˋ = new o.ik.a(this) {
                final /* synthetic */ e ˎ;

                {
                    this.ˎ = r1;
                }

                public void ˋ(boolean z) {
                    this.ˎ.ˋ(z);
                }
            };
            ik.ॱ(this.ˎ, this.ˋ);
            ˋ(this.ˎ.isTouchExplorationEnabled());
        }

        private void ˋ(boolean z) {
            setClickable(!z);
            setFocusable(z);
        }

        protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
            super.onLayout(z, i, i2, i3, i4);
            if (this.ˏ != null) {
                this.ˏ.ॱ(this, i, i2, i3, i4);
            }
        }

        protected void onAttachedToWindow() {
            super.onAttachedToWindow();
            if (this.ˊ != null) {
                this.ˊ.ˊ(this);
            }
            ViewCompat.ᐝॱ(this);
        }

        protected void onDetachedFromWindow() {
            super.onDetachedFromWindow();
            if (this.ˊ != null) {
                this.ˊ.ˎ(this);
            }
            ik.ˎ(this.ˎ, this.ˋ);
        }

        void ˏ(c cVar) {
            this.ˏ = cVar;
        }

        void ˏ(a aVar) {
            this.ˊ = aVar;
        }
    }

    static {
        boolean z = VERSION.SDK_INT >= 16 && VERSION.SDK_INT <= 19;
        ˋ = z;
    }

    protected void ˊ(int i) {
        asr.ॱ().ˊ(this.ˊ, i);
    }

    public boolean ˎ() {
        return asr.ॱ().ˎ(this.ˊ);
    }

    protected SwipeDismissBehavior<? extends View> ॱ() {
        return new Behavior();
    }

    final void ˏ() {
        if (this.ˏ.getParent() == null) {
            LayoutParams layoutParams = this.ˏ.getLayoutParams();
            if (layoutParams instanceof androidx.coordinatorlayout.widget.CoordinatorLayout.a) {
                androidx.coordinatorlayout.widget.CoordinatorLayout.a aVar = (androidx.coordinatorlayout.widget.CoordinatorLayout.a) layoutParams;
                androidx.coordinatorlayout.widget.CoordinatorLayout.Behavior ॱ = this.ॱॱ == null ? ॱ() : this.ॱॱ;
                if (ॱ instanceof Behavior) {
                    ((Behavior) ॱ).ˏ(this);
                }
                ॱ.ˎ(new SwipeDismissBehavior.d(this) {
                    final /* synthetic */ BaseTransientBottomBar ˎ;

                    {
                        this.ˎ = r1;
                    }

                    public void ˎ(View view) {
                        view.setVisibility(8);
                        this.ˎ.ˊ(0);
                    }

                    public void ॱ(int i) {
                        switch (i) {
                            case 0:
                                asr.ॱ().ॱ(this.ˎ.ˊ);
                                return;
                            case 1:
                            case 2:
                                asr.ॱ().ˏ(this.ˎ.ˊ);
                                return;
                            default:
                                return;
                        }
                    }
                });
                aVar.ˊ(ॱ);
                aVar.ॱॱ = 80;
            }
            this.ʼ.addView(this.ˏ);
        }
        this.ˏ.ˏ(new a(this) {
            final /* synthetic */ BaseTransientBottomBar ˊ;

            {
                this.ˊ = r1;
            }

            public void ˊ(View view) {
            }

            public void ˎ(View view) {
                if (this.ˊ.ˎ()) {
                    BaseTransientBottomBar.ˎ.post(new Runnable(this) {
                        final /* synthetic */ AnonymousClass4 ˎ;

                        {
                            this.ˎ = r1;
                        }

                        public void run() {
                            this.ˎ.ˊ.ˎ(3);
                        }
                    });
                }
            }
        });
        if (!ViewCompat.ˊᐝ(this.ˏ)) {
            this.ˏ.ˏ(new c(this) {
                final /* synthetic */ BaseTransientBottomBar ˏ;

                {
                    this.ˏ = r1;
                }

                public void ॱ(View view, int i, int i2, int i3, int i4) {
                    this.ˏ.ˏ.ˏ(null);
                    if (this.ˏ.ʽ()) {
                        this.ˏ.ˋ();
                    } else {
                        this.ˏ.ˊ();
                    }
                }
            });
        } else if (ʽ()) {
            ˋ();
        } else {
            ˊ();
        }
    }

    void ˋ() {
        final int ॱॱ = ॱॱ();
        if (ˋ) {
            ViewCompat.ʽ(this.ˏ, ॱॱ);
        } else {
            this.ˏ.setTranslationY((float) ॱॱ);
        }
        ValueAnimator valueAnimator = new ValueAnimator();
        valueAnimator.setIntValues(new int[]{ॱॱ, 0});
        valueAnimator.setInterpolator(aqv.ॱ);
        valueAnimator.setDuration(250);
        valueAnimator.addListener(new AnimatorListenerAdapter(this) {
            final /* synthetic */ BaseTransientBottomBar ॱ;

            {
                this.ॱ = r1;
            }

            public void onAnimationStart(Animator animator) {
                this.ॱ.ᐝ.ˏ(70, 180);
            }

            public void onAnimationEnd(Animator animator) {
                this.ॱ.ˊ();
            }
        });
        valueAnimator.addUpdateListener(new AnimatorUpdateListener(this) {
            final /* synthetic */ BaseTransientBottomBar ˊ;
            private int ॱ = ॱॱ;

            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                int intValue = ((Integer) valueAnimator.getAnimatedValue()).intValue();
                if (BaseTransientBottomBar.ˋ) {
                    ViewCompat.ʽ(this.ˊ.ˏ, intValue - this.ॱ);
                } else {
                    this.ˊ.ˏ.setTranslationY((float) intValue);
                }
                this.ॱ = intValue;
            }
        });
        valueAnimator.start();
    }

    private void ॱ(final int i) {
        ValueAnimator valueAnimator = new ValueAnimator();
        valueAnimator.setIntValues(new int[]{0, ॱॱ()});
        valueAnimator.setInterpolator(aqv.ॱ);
        valueAnimator.setDuration(250);
        valueAnimator.addListener(new AnimatorListenerAdapter(this) {
            final /* synthetic */ BaseTransientBottomBar ˊ;

            public void onAnimationStart(Animator animator) {
                this.ˊ.ᐝ.ˎ(0, 180);
            }

            public void onAnimationEnd(Animator animator) {
                this.ˊ.ˎ(i);
            }
        });
        valueAnimator.addUpdateListener(new AnimatorUpdateListener(this) {
            private int ˎ = 0;
            final /* synthetic */ BaseTransientBottomBar ॱ;

            {
                this.ॱ = r2;
            }

            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                int intValue = ((Integer) valueAnimator.getAnimatedValue()).intValue();
                if (BaseTransientBottomBar.ˋ) {
                    ViewCompat.ʽ(this.ॱ.ˏ, intValue - this.ˎ);
                } else {
                    this.ॱ.ˏ.setTranslationY((float) intValue);
                }
                this.ˎ = intValue;
            }
        });
        valueAnimator.start();
    }

    private int ॱॱ() {
        int height = this.ˏ.getHeight();
        LayoutParams layoutParams = this.ˏ.getLayoutParams();
        if (layoutParams instanceof MarginLayoutParams) {
            return ((MarginLayoutParams) layoutParams).bottomMargin + height;
        }
        return height;
    }

    final void ˏ(int i) {
        if (ʽ() && this.ˏ.getVisibility() == 0) {
            ॱ(i);
        } else {
            ˎ(i);
        }
    }

    void ˊ() {
        asr.ॱ().ˋ(this.ˊ);
        if (this.ʽ != null) {
            for (int size = this.ʽ.size() - 1; size >= 0; size--) {
                ((BaseCallback) this.ʽ.get(size)).ॱ(this);
            }
        }
    }

    void ˎ(int i) {
        asr.ॱ().ˊ(this.ˊ);
        if (this.ʽ != null) {
            for (int size = this.ʽ.size() - 1; size >= 0; size--) {
                ((BaseCallback) this.ʽ.get(size)).ˊ(this, i);
            }
        }
        ViewParent parent = this.ˏ.getParent();
        if (parent instanceof ViewGroup) {
            ((ViewGroup) parent).removeView(this.ˏ);
        }
    }

    boolean ʽ() {
        List enabledAccessibilityServiceList = this.ʻ.getEnabledAccessibilityServiceList(1);
        if (enabledAccessibilityServiceList == null || !enabledAccessibilityServiceList.isEmpty()) {
            return false;
        }
        return true;
    }
}
